﻿namespace rtgen_guiclient
{
    using System;
    using System.Collections;

    internal class CHashList
    {
        public ArrayList qHashList = new ArrayList();

        public void AddHash(CHash oHash)
        {
            this.qHashList.Add(oHash);
        }

        public CHash GetAvailableHash()
        {
            lock (this.qHashList.SyncRoot)
            {
            }
            IEnumerator enumerator = this.qHashList.GetEnumerator();
            while (enumerator.MoveNext())
            {
                CHash current = (CHash) enumerator.Current;
                if (current.IsNotAssigned())
                {
                    current.Assign();
                    return current;
                }
            }
            return null;
        }

        public CHash GetFinishedHash()
        {
            lock (this.qHashList.SyncRoot)
            {
            }
            IEnumerator enumerator = this.qHashList.GetEnumerator();
            while (enumerator.MoveNext())
            {
                CHash current = (CHash) enumerator.Current;
                if (current.IsFinished())
                {
                    return current;
                }
            }
            return null;
        }

        public bool IsAnyAvailable()
        {
            lock (this.qHashList.SyncRoot)
            {
            }
            IEnumerator enumerator = this.qHashList.GetEnumerator();
            while (enumerator.MoveNext())
            {
                CHash current = (CHash) enumerator.Current;
                if (current.IsNotAssigned())
                {
                    return true;
                }
            }
            return false;
        }

        public void RemoveHash(CHash oHash)
        {
            lock (this.qHashList.SyncRoot)
            {
            }
            IEnumerator enumerator = this.qHashList.GetEnumerator();
            while (enumerator.MoveNext())
            {
                CHash current = (CHash) enumerator.Current;
                if (oHash.GetID() == current.GetID())
                {
                    this.qHashList.Remove(current);
                    return;
                }
            }
        }
    }
}

